home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / wattcp / include / tcp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  8.6 KB  |  288 lines

  1. #define getsockname hack_getsockname
  2. #define sockaddr hack_sockaddr
  3. #define in_addr hack_in_addr
  4. /*
  5.  * Waterloo TCP
  6.  *
  7.  * Copyright (c) 1990, 1991, 1992, 1993 Erick Engelke
  8.  *
  9.  * Portions copyright others, see copyright.h for details.
  10.  *
  11.  * This library is free software; you can use it or redistribute under
  12.  * the terms of the license included in LICENSE.H.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * file LICENSE.H for more details.
  18.  *
  19.  */
  20. #ifndef WTCP_VER
  21.  
  22. /* handle some early dumb naming conventions */
  23. #define dbuginit()      dbug_init()
  24.  
  25. /* Kernal version (major major minor minor) */
  26. #define WTCP_VER 0x0102
  27.  
  28. /*
  29.  * Typedefs and constants
  30.  */
  31.  
  32. #ifndef byte
  33. typedef unsigned char byte;
  34. #endif  byte
  35. #ifndef word
  36. typedef unsigned int word;
  37. #endif  word
  38. #ifndef longword
  39. typedef unsigned long longword;
  40. #endif  longword
  41.  
  42. typedef struct {
  43.     byte undoc[ 4300 ];
  44. } tcp_Socket;
  45.  
  46. typedef struct {
  47.     byte undoc[ 2200 ];
  48. } udp_Socket;
  49.  
  50.  
  51. typedef struct sockaddr {
  52.     word        s_type;
  53.     word        s_port;
  54.     longword    s_ip;
  55.     byte        s_spares[6];    /* unused in TCP realm */
  56. };
  57.  
  58. #define sockaddr_in sockaddr
  59.  
  60. typedef struct in_addr {
  61.     longword    s_addr;
  62. };
  63.  
  64.  
  65. #define MAX_COOKIES     10
  66. #define MAX_NAMESERVERS 10
  67.  
  68. #define TCP_MODE_BINARY 0
  69. #define TCP_MODE_ASCII    1
  70. #define UDP_MODE_CHK    0    /*default to checksum */
  71. #define UDP_MODE_NOCHK    2
  72. #define TCP_MODE_NAGLE  0       /* Nagle algorithm */
  73. #define TCP_MODE_NONAGLE 4
  74.  
  75. extern sock_init();
  76. /*
  77.  *   s is the pointer to a udp or tcp socket
  78.  */
  79. extern sock_read(void  *s, byte *dp, int len );
  80. extern sock_fastread(void  *s, byte *dp, int len );
  81. extern sock_write(void  *s, byte *dp, int len);
  82. extern void sock_enqueue(void  *s, byte *dp, int len);
  83. extern sock_fastwrite(void *s, byte *dp, int len );
  84. extern sock_flush( void  *s );
  85. extern sock_flushnext( void  *s);
  86. extern sock_puts( void  *s, byte *dp );
  87. extern word sock_gets( void  *s, byte *dp, int n );
  88. extern byte sock_putc( void  *s, byte c );
  89. extern byte sock_getc( void  *s );
  90. extern word sock_dataready( void  *s );
  91. extern sock_close( void *s );
  92. extern sock_abort( void *s );
  93. extern sock_printf( void  *s, char *format, ... );
  94. extern sock_scanf( void  *s, char *format, ... );
  95. extern sock_mode( void *s, word mode );        /* see TCP_MODE_... */
  96. extern void db_write( char *msg );
  97. extern void dbug_init();
  98. extern void dbug_printf(char *,... );
  99.  
  100. /*
  101.  * TCP or UDP specific stuff, must be used for open's and listens, but
  102.  * sock stuff is used for everything else
  103.  */
  104. extern int udp_open(void *s, word lport, longword ina, word port, int (*datahandler)());
  105. extern int tcp_open(void *s, word lport, longword ina, word port, int (*datahandler)());
  106. extern tcp_listen(void *s, word lport, longword ina, word port, int (*datahandler)(), word timeout);
  107. extern int tcp_established(void *s);
  108. extern char *rip( char *s );
  109. extern longword resolve( char *name);
  110. /*
  111.  * less general functions
  112.  */
  113. extern longword aton( char *text );
  114. extern int isaddr( char *text );
  115. extern tcp_cbreak( word mode );
  116. extern longword intel( longword x );
  117. extern word intel16( word x );
  118.  
  119. /*
  120.  * timers
  121.  */
  122.  
  123. extern void ip_timer_init( void *s , word delayseconds );
  124. extern word ip_timer_expired( void *s );
  125.         /*
  126.          * TCP/IP system variables - do not change these since they
  127.          *      are not necessarily the source variables, instead use
  128.          *      ip_Init function
  129.          */
  130. extern longword my_ip_addr;
  131. extern longword sin_mask;       /* eg.  0xfffffe00L */
  132. extern word sock_delay;
  133.  
  134.         /*
  135.          * tcp_init/tcp_shutdown
  136.          *      - init/kill all tcp and lower services
  137.          *      - only call if you do not use sock_init
  138.          * (NOT RECOMMENDED)
  139.          */
  140. extern tcp_shutdown();
  141. extern tcp_Init();
  142.  
  143. /*
  144.  * things you probably won't need to know about
  145.  */
  146.     /*
  147.      * sock_debugdump
  148.      *    - dump some socket control block parameters
  149.      * used for testing the kernal, not recommended
  150.      */
  151. extern sock_debugdump( void *s);
  152.         /*
  153.          * tcp_config - read a configuration file
  154.          *            - if special path desired, call after sock_init()
  155.          *            - null reads path from executable
  156.          * see sock_init();
  157.          */
  158. extern tcp_config( char *path );
  159.         /*
  160.          * tcp_tick - called periodically by user application in sock_wait_...
  161.          *          - returns 1 when our socket closes
  162.          */
  163. extern tcp_tick( void *s );
  164.         /*
  165.          * Retransmitter - called periodically to perform tcp retransmissions
  166.          *          - normally called from tcp_tick, you have to be pretty
  167.          *            low down to use this one
  168.          */
  169. extern tcp_Retransmitter();
  170.         /*
  171.          * tcp_set_debug_state - set 1 or reset 0 - depends on what I have done
  172.          */
  173. extern tcp_set_debug_state( word x );
  174.  
  175.  
  176. extern int _last_cookie;
  177. extern longword _cookie[MAX_COOKIES];
  178.  
  179.         /*
  180.          * name domain constants
  181.          */
  182.  
  183. extern char *def_domain;
  184. extern longword def_nameservers[ MAX_NAMESERVERS ];
  185.  
  186.  
  187. extern word wathndlcbrk;
  188. extern word watcbroke;
  189. /*
  190.  * sock_wait_... macros
  191.  */
  192. /*
  193.  * sock_wait_established()
  194.  *    - waits then aborts if timeout on s connection
  195.  * sock_wait_input()
  196.  *    - waits for received input on s
  197.  *    - may not be valid input for sock_Gets... check returned length
  198.  * sock_tick()
  199.  *    - do tick and jump on abort
  200.  * sock_wait_closed();
  201.  *    - discards all received data
  202.  *
  203.  * jump to sock_err with contents of *statusptr set to
  204.  *     1 on closed
  205.  *    -1 on timeout
  206.  *
  207.  */
  208. extern int _ip_delay0( void *s, int seconds, int (*fn)(), void *statusptr );
  209. extern int _ip_delay1( void *s, int seconds, int (*fn)(), void *statusptr );
  210. extern int _ip_delay2( void *s, int seconds, int (*fn)(), void *statusptr );
  211.  
  212. extern unsigned long set_timeout( unsigned int seconds );
  213. extern unsigned long set_ttimeout( unsigned int ticks );
  214. extern int chk_timeout( unsigned long timeout );
  215.  
  216.  
  217.  
  218. extern int tcp_tick( void *s );
  219.  
  220. #define sock_wait_established( s, seconds, fn, statusptr ) \
  221.     if (_ip_delay0( s, seconds, fn, statusptr )) goto sock_err;
  222. #define sock_wait_input( s, seconds, fn , statusptr ) \
  223.     if (_ip_delay1( s, seconds, fn, statusptr )) goto sock_err;
  224. #define sock_tick( s, statusptr ) \
  225.     if ( !tcp_tick(s)) { if (statusptr) *statusptr = 1 ; goto sock_err; }
  226. #define sock_wait_closed(s, seconds, fn, statusptr )\
  227.     if (_ip_delay2( s, seconds, fn, statusptr )) goto sock_err;
  228.  
  229. /* user initialization file */
  230. extern void (*usr_init)();
  231.  
  232. extern void outs( char far * string );
  233. extern longword aton( char * string);
  234. extern int _ping( longword host , longword countnum );
  235. extern longword _chk_ping( longword host , longword *ptr);
  236. extern void _arp_register( longword use, longword instead_of );
  237.  
  238.  
  239.  
  240. extern void _eth_init();
  241. extern byte *_eth_formatpacket( void *eth_dest, word eth_type );
  242. extern void _eth_send( word len);
  243. extern void _eth_free( void *buf);
  244. extern byte *_eth_arrived( word *type_ptr);
  245. extern void _eth_release();
  246.  
  247.  
  248.  
  249. /* bsd-similar stuff */
  250.  
  251. extern int sock_rbsize( void *s );
  252. extern int sock_rbused( void *s );
  253. extern int sock_rbleft( void *s );
  254. extern int sock_tbsize( void *s );
  255. extern int sock_tbused( void *s );
  256. extern int sock_tbleft( void *s );
  257.  
  258.  
  259. extern _chk_socket( tcp_Socket *s );
  260. extern char *inet_ntoa( char *s, longword x );
  261. extern char *psocket( tcp_Socket *s );
  262. extern longword inet_addr( char *s );
  263. extern char *sockerr( tcp_Socket *s );
  264. extern char *sockstate( tcp_Socket *s );
  265. extern getpeername( tcp_Socket *s, void *dest, int *len );
  266. extern getsockname(  tcp_Socket *s, void *dest, int *len );
  267. extern longword gethostid();
  268. extern longword sethostid( longword ip );
  269. extern char *getdomainname( char *name, int length );
  270. extern char *setdomainname( char *string );
  271. extern char *gethostname( char *name, int length );
  272. extern char *sethostname( char *string );
  273. extern word ntohs( word a );
  274. extern word htons( word a );
  275. extern longword ntohl( longword x );
  276. extern longword htonl( longword x );
  277.  
  278. extern void _arp_register( longword use, longword instead_of );
  279. extern int _arp_resolve( longword ina, void *ethap, int nowait );
  280.  
  281. extern _survivebootp;
  282.  
  283. extern sock_stats( tcp_Socket *s, word *days, word *inactive, word *cwindow, word *avg, word *sd );
  284. extern int addwattcpd( void (*p)() );
  285. extern int delwattcpd( void (*p)() );
  286. extern int tap_add( void *socket, void *userid );
  287. #endif /* WTCP_VER */
  288.